<template>
    <div class="container">
      <div id="map"></div>
    </div>
  </template>
  
  <script>
  import mapboxgl from "mapbox-gl"; // or "const mapboxgl = require('mapbox-gl');"
  export default {
    name: "Vue2MapboxFirstmapboxMap",
    data() {
      return {};
    },
  
    mounted() {
      this.initMap();
    },
  
    methods: {
      initMap() {
        mapboxgl.accessToken =
          "pk.eyJ1IjoiY3Vpaml5aW5nIiwiYSI6ImNsZ3QyZjY4ODAxbDEza3BkOTJqbTJvN3gifQ.Ldj9qAFzb5uzcLP-VtFB3A";
        const map = new mapboxgl.Map({
          container: "map",
          style: "mapbox://styles/mapbox/streets-v11",
          center: [118.995, 40.730], 
          // projection: "mercator",
          zoom: 15
        });

        const geojsonData = {
        type: 'FeatureCollection',
        features: [
          {
            type: 'Feature',
            geometry: {
              type: 'Polygon',
              coordinates: [
                [
                  [118.997, 40.730],
                  [118.996, 40.731],
                  [118.995, 40.730],
                  [118.996, 40.729],
                  [118.997, 40.730]
                ]
              ]
            },
            properties: {
              height: 100, // 建筑物的高度
              min_height: 10, // 建筑物的最小高度
            }
          }
        ]
      }
      // 
      map.on('load', () => {
        map.addSource('building-test', {
          type: 'geojson',
          data: geojsonData
        })
        map.addLayer({
          id: 'building-test-3d',
          type: 'fill-extrusion',
          source: 'building-test',
          paint: {
            'fill-extrusion-color': '#ffffff',
            'fill-extrusion-height': ['get', 'height'],
            'fill-extrusion-base': ['get', 'min_height'],
            'fill-extrusion-opacity': 0.8
          }
        })

        map.setLight({
          anchor: 'viewport',
          color: '#ffffff',
          intensity: 0.8,
        });
      })
  
  
  
      },
    },
  };
  </script>
  
  <style ></style>
  